package com.mms.pojo;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by dangz on 2017/5/18/018.
 */
@Entity
@Table(name = "sys_role")
public class SysRole implements Serializable {
    @NotNull(message = "角色代码不能为空")
    @Size(min = 2, max = 20, message = "角色代码长度只能在2-20之间")
    private String code;
    @NotNull(message = "角色名称不能为空")
    @Size(min = 2, max = 20, message = "角色名称长度只能在2-20之间")
    private String name;
    private String remark;
    private Set<SysManager> sysManagers = new HashSet<SysManager>(0);
    private Set<SysOperate> sysOperates = new HashSet<SysOperate>(0);

    @Id
    @Column(name = "CODE", unique = true, nullable = false, length = 50)
    public String getCode() {
        return this.code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    @Column(name = "NAME", nullable = false, length = 50)
    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "REMARK", length = 2000)
    public String getRemark() {
        return this.remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "sysRole")
    public Set<SysManager> getSysManagers() {
        return this.sysManagers;
    }

    public void setSysManagers(Set<SysManager> sysManagers) {
        this.sysManagers = sysManagers;
    }

    @ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
    @JoinTable(name = "sys_role_operate", joinColumns = { @JoinColumn(name = "ROLE", nullable = false, updatable = false) }, inverseJoinColumns = {
            @JoinColumn(name = "MENU", nullable = false, updatable = false),
            @JoinColumn(name = "OP", nullable = false, updatable = false) })
    public Set<SysOperate> getSysOperates() {
        return this.sysOperates;
    }

    public void setSysOperates(Set<SysOperate> sysOperates) {
        this.sysOperates = sysOperates;
    }
}
